<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="stylesheet" th:href="@{/layui/css/layui.css}">
<script  th:src="@{/js/jquery-1.11.3.min.js}"></script>
<script  th:src="@{/layui/layui.js}"></script>
<script  th:src="@{/js/util.js}"></script>
<body>
<h1>这是密码修改页</h1>

<form class="layui-form" id="modifyPasswordFrom">
    <div id="modifyPasswordDiv">
        <div class="layui-form" lay-filter="modifyPasswordFrom" style="margin: 10px 20px;">
            <div class="layui-form-item">
                <label class="layui-form-label">原密码<font color="red">*</font></label>
                <div class="layui-input-inline">
                    <input type="password" id="oldPassword" name="oldPassword"
                           lay-verify="required" placeholder="" autocomplete="off"
                           class="layui-input" maxlength="14" required="required">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码<font color="red">*</font></label>
                <div class="layui-input-inline">
                    <input type="password" id="newPassword" name="newPassword"
                           placeholder="" autocomplete="off" class="layui-input"
                           maxlength="14" lay-verify="required" required="required">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码<font color="red">*</font></label>
                <div class="layui-input-inline">
                    <input type="password" id="newPassword2" name="newPassword2"
                           placeholder="" autocomplete="off" class="layui-input"
                           maxlength="14" lay-verify="required" required="required">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-inline" style="padding-left: 30px">
                    <button type="button" class="layui-btn"  lay-submit lay-filter="modifyPasswordFrom" >立即提交</button>
                </div>
            </div>

        </div>
    </div>
</form>


</body>
<script type="text/javascript" th:inline="javascript">

    $(function() {
        layui.use(['form', 'layer'], function () {

            var form = layui.form;
            var layer=layui.layer;
            form.on('submit(modifyPasswordFrom)',function(data){
                var param = {};


                param.oldPassword = $("#oldPassword").val();
                param.newPassword = $("#newPassword").val();
                param.newPassword2 = $("#newPassword2").val();

                $.ajax({
                    url: '/login/modifyPassword2',
                    dataType: 'json',
                    contentType: "application/json",
                    type: 'post',
                    async: false,
                    data: JSON.stringify(param),
                    success: function (result) {
                        if (result.status == 200) {
                            $("#oldPassword").val("");
                            $("#newPassword").val("");
                            $("#newPassword2").val("");
                            layer.msg("修改成功，请重新登录！");
                            window.setTimeout(function () {
                                window.location.href = "/";
                            }, 800);
                        } else {
                            layer.msg(result.msg);
                        }
                    }
                })
            })
            form.render();
        })
    })


</script>
</html>